<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<title>EZ Morning 飞鱼秀</title>

<!-- 最新 Bootstrap 核心 CSS 文件 -->
<link rel="stylesheet" href="http://cdn.bootcss.com/twitter-bootstrap/3.0.3/css/bootstrap.min.css">

<link href="../css/bootstrap-datetimepicker.min.css" rel="stylesheet"> 
<style type="text/css">
hr {
	height: 1px;
	border: none;
	border-top: 1px dashed #0066CC;
}
</style>
</head>
<body>


 <div class="container">
 
  <h1>飞鱼秀收听地址</h1>
 
     
	 选择年月
	 <br/>
	 <input type="text"   id="month"  data-date=""  data-date-format="MM yyyy"   data-link-format="yyyymm" />
	 <br/>
	 或者起始终止日期<br/>
	 <input id="startDay" type="text" />
	 <br/>~<br/>
	 <input id="endDay" type="text" /> 
	 <br/>
	  
	 <hr/>
	 <label class="radio-inline">
       <input type="radio" name="version" value="1" /> 版本1 long, long ago~201303 
     </label>     
         
     <br>
     <label class="radio-inline">
       <input type="radio" name="version"  value="2" checked />  版本2 2013-07-01~至今
     </label>
 
     <hr/>
	 
	 过滤的星期
	 <label class="checkbox-inline">
       <input type="checkbox" id="disableddayofweek_6" value="6" checked /> 周六
     </label>
     <label class="checkbox-inline">
       <input type="checkbox" id="disableddayofweek_0" value="0" checked /> 周天
     </label> 
     
      <hr/>
	 
		<input class="btn btn-default" onclick="getPlay()" type="button" value="网页播放" /> 
		<input class="btn btn-default" onclick="getHref()" type="button" value="网页超链接" /> 
		<input class="btn btn-default" onclick="getAddress()" type="button" value="下载地址" /> 
		<input class="btn btn-default" onclick="getPlaylist()" type="button" value="播放列表(另存为wpl文件)" />
 
	  <hr/>

 
    <p id="p1"  style="display: none;">
      <select class="form-control" id="audioSelect" onchange="player()"> </select>
      <audio  id="audioPlayer" controls="controls" style="width: 100%;"></audio>
    </p>
   <p id="p2" style="display: none;"> <span id="EZHref"> </span> </p> 
 	<p id="p3" style="display: none;">
		<input class="buttonStyle" onclick="checkAll()" type="button"
			value="全选" /> <span class="explain">请按Ctrl+c 复制到剪切板</span><br />
		<textarea id="textarea_result"  class="form-control" style="height: 200px;"></textarea>
	</p>
	
 </div>
 
<!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
<script src="http://cdn.bootcss.com/jquery/2.1.1/jquery.min.js"></script> 
<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script src="http://cdn.bootcss.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>

<script src="../js/bootstrap-datetimepicker.min.js"></script>
<script src="../js/locales/bootstrap-datetimepicker.zh-CN.js"></script>
 
<script type="text/javascript"> 

var ezMorningMMS = new Array();//MMS协议地址
var index;
var resultTemp = "";

var audioPlayer, audioSelect,EZHref,p1,p2,p3,textarea_result;

var disableddayofweek_0,disableddayofweek_6;

var version;

//完整的例子:mms://media.chinabroadcast.cn/eng/music/morning/2012/1015a.wma;
var preMMS1 = "mms://media.chinabroadcast.cn/eng/music/morning/";

//地址的前半部分
//完整的例子:http://mod.cri.cn/eng/ez/morning/2013/ezm130813.mp3;
var preMMS2 = "http://mod.cri.cn/eng/ez/morning/";
  
 $(function(){
	 
    $('#month').datetimepicker({ language:  'zh-CN' ,format: 'yyyy-mm',startView:3,minView:3,autoclose:true});
    $('#startDay,#endDay').datetimepicker({ language:  'zh-CN' ,format: 'yyyy-mm-dd',minView:2,autoclose:true});
 
    audioPlayer = document.getElementById("audioPlayer");
    audioSelect = document.getElementById("audioSelect");
    p1 = document.getElementById("p1");
    p2 = document.getElementById("p2");
    p3 = document.getElementById("p3");

    disableddayofweek_0 = document.getElementById("disableddayofweek_0");
    disableddayofweek_6 = document.getElementById("disableddayofweek_6");

    EZHref = document.getElementById("EZHref");
    textarea_result = document.getElementById("textarea_result");
    
    var date = new Date();
    var dateStr = date.getFullYear()*10000+date.getMonth()*100+100+date.getDate()+"";
    document.getElementById("startDay").value = dateStr.substr(0,4)+"-"+dateStr.substr(4,2)+"-"+dateStr.substr(6,2);
    document.getElementById("endDay").value = dateStr.substr(0,4)+"-"+dateStr.substr(4,2)+"-"+dateStr.substr(6,2);
    
    getPlay();
 
 });  


 
 function player(){
	 audioPlayer.src=audioSelect.value;
	 audioPlayer.play();
 }
 
 function getPlay(){
	
		p1.style.display='inline'; 
		p2.style.display='none'; 
		p3.style.display='none'; 
		
	    resultTemp = "";
		getMms();
		//<video src="/i/movie.ogg" controls="controls">your browser does not support the video tag</video>
		for (index in ezMorningMMS){
/* 	          resultTemp = resultTemp 
	                              +"<br/>"+ ezMorningMMS[index].substring(ezMorningMMS[index].lastIndexOf("/")+1,ezMorningMMS[index].length) 
	                              + "<br/><audio  controls='controls'  src='"+ezMorningMMS[index] +"'>您的浏览器不支持 video 标签。</audio> "
	                              +""; */
	          resultTemp = resultTemp 
              +"<option value='"+ezMorningMMS[index] +"'>"
              + ezMorningMMS[index].substring(ezMorningMMS[index].lastIndexOf("/")+1,ezMorningMMS[index].length)
              + "</option>";
		}
		if(ezMorningMMS.length>0){
			 audioPlayer.src=ezMorningMMS[0];
			 audioPlayer.play();
		}
		 
		audioSelect.innerHTML = resultTemp; 
 }
 
//获得超链接 
function getHref(){

	p2.style.display='inline'; 
	p1.style.display='none'; 
	p3.style.display='none'; 

    resultTemp = "&nbsp;&nbsp;&nbsp;&nbsp;<br>";
	getMms();
	
	for (index in ezMorningMMS){
          resultTemp = resultTemp + "<a target='_blank' href='"+ezMorningMMS[index] +"'>"+ezMorningMMS[index]+ "</a></br>";
	}
    EZHref.innerHTML=resultTemp;
}
//获得地址
function getAddress(){

	p3.style.display='inline'; 
	p2.style.display='none'; 
	p1.style.display='none'; 

	resultTemp = "";
	getMms();
	for (index in ezMorningMMS){
		resultTemp = resultTemp + ezMorningMMS[index]+ "\r\n";
	}
	textarea_result.innerHTML=resultTemp;
}
//获得播放列表
function getPlaylist(){//&quot;

	p3.style.display='inline'; 
	p2.style.display='none'; 
	p1.style.display='none'; 

	var preWPL="<?wpl version=&quot;1.0&quot;?>\r\n"
			+"<smil>\r\n"
			+"&nbsp;&nbsp;&nbsp;&nbsp;<head>\r\n"
			+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<meta name=&quot;Generator&quot;&nbsp;content=&quot;Microsoft Windows Media Player -- 12.0.7601.17514&quot;/>\r\n"
			+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<meta name=&quot;ItemCount&quot;&nbsp;content=&quot;1&quot;/>\r\n"
			+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<author/>\r\n"
			+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<title>EZ Morning</title>\r\n"
			+"&nbsp;&nbsp;&nbsp;&nbsp;</head>\r\n"
			+"&nbsp;&nbsp;&nbsp;&nbsp;<body>\r\n"
			+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<seq>\r\n"
			;
	var postWPL="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</seq>\r\n"
	        +"&nbsp;&nbsp;&nbsp;&nbsp;</body>\r\n"
	        +"</smil>\r\n"
            ;
	getMms();
	resultTemp = "";
	for (index in ezMorningMMS){
		resultTemp = resultTemp +"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
		           +"<media src=&quot;"+ ezMorningMMS[index] + "&quot;/>\r\n";
	}
	textarea_result.innerHTML=preWPL+resultTemp+postWPL;
}

function getMms(){//获得MMS协议地址
	
	ezMorningMMS = new Array();

	version = $("input[name='version']:checked").val();
	
	var month = document.getElementById("month").value;
	var startDay = document.getElementById("startDay").value;
	var endDay = document.getElementById("endDay").value;
	
	var startDate = new Date(); //起始时间
	var endDate = new Date();   //终止时间
	var tempDate =new Date();   //中间变量
	
	var monthTemp; //月份中间变量
	var dayTemp;   //日期中间变量

	if(month!=""){//如果填写的月份不为空
		startDate.setFullYear(Number(month.substr(0,4)),Number(month.substr(5,3))-Number(1),1);
		endDate.setFullYear(Number(month.substr(0,4)),Number(month.substr(5,3)),1);
		endDate.setTime(endDate.getTime()-1000*60*60*24);  //结束时间减一天,获得月末时间

	}else{//读取用户填写的起始终止时间
		startDate.setFullYear(Number(startDay.substr(0,4)),Number(startDay.substr(5,2))-Number(1),Number(startDay.substr(8,2)));
		endDate.setFullYear(Number(endDay.substr(0,4)),Number(endDay.substr(5,2))-Number(1),Number(endDay.substr(8,2))+1);	
	}
	
	tempDate.setTime(startDate.getTime());
    
	var j=0;
	var dateStr = "";//字符串日期 yyyyMMdd
	for(var i=0;tempDate<endDate;i++){
		 
		dateStr = tempDate.getFullYear()*10000 + (tempDate.getMonth()+1)*100 + tempDate.getDate();
		dateStr += "";//转换成字符串20140821
 
		if(disableddayofweek_0.checked && disableddayofweek_0.value==tempDate.getDay()){//是否过滤周天
			
		}else if(disableddayofweek_6.checked && disableddayofweek_6.value==tempDate.getDay()){//是否过滤周六

		}else{
			if(version == 1){
				//2012/1015a.wma
				ezMorningMMS[3*j+0]=preMMS1+tempDate.getFullYear()+"/"+dateStr.substring(4)+"a.wma";
			    ezMorningMMS[3*j+1]=preMMS1+tempDate.getFullYear()+"/"+dateStr.substring(4)+"b.wma";
				ezMorningMMS[3*j+2]=preMMS1+tempDate.getFullYear()+"/"+dateStr.substring(4)+"c.wma";
				j++;	
			}else if(version == 2){
				//20140813  2012/1015a.wma now 2014/ezm140813.mp3
				ezMorningMMS[j]=preMMS2+tempDate.getFullYear()+"/ezm"+dateStr.substring(2)+".mp3";
				j++;
			}
		}
		tempDate.setTime(startDate.getTime()+(i+1)*1000*60*60*24);//前进一天
	}
}

function checkAll(){
	textarea_result.select();
}
</script>
 
</body>
</html>